import  pymongo
class DbUtils(object):
    def __init__(self,dbname='test',collectionname=''):
        #实例化self.db
        exec("self.db=pymongo.MongoClient('localhost', 27017)."+dbname)
        #给要操作的集合赋值
        exec("self.collection=self.db."+collectionname)

    def storage(self,data=[]):
        return  True if self.collection.insert_many(data) else False
    def update(self,old={},new={}):
        return  True if self.collection.update(old,{'$set':new}) else False
    def select(self,where={},field=[],limits=3,ordering=[]):
        return self.collection.find(where,field).limit(limits).sort(ordering)
    def delete(self,field={}):
        return  True if self.collection.remove(field) else False
if __name__=='__main__':
        dbutils=DbUtils('test','iptable')




